var prefix = "/evaluation";
$().ready(function() {
    validateRule();
});
$.validator.setDefaults({
    /*ignore:":hidden:not(select)",*/
    submitHandler : function() {
        save();
    }
});
function save() {
    $.ajax({
        cache : true,
        type : "POST",
        url : prefix + "/saveTeacher",
        data : $('#evaluationForm').serialize(),
        async : false,
        error : function(request) {
            layer.alert("评价失败！",{icon: 2});
        },
        success : function(data) {
            if (data.code == 0) {
                layer.msg("评价成功！",{icon: 1});
                var index = layer.getFrameIndex(window.name);
                console.log(index)
                setTimeout(function(){
                    parent.layer.close(index);//关闭弹出层
                    parent.location.reload();//更新父级页面（提示：如果需要跳转到其它页面见下文）
                }, 2000);

            } else {
                layer.alert("评价失败！",{icon: 2})
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#evaluationForm").validate({
        errorPlacement:function (error, element) {
            //error.appendTo(element.parent());
            if (element.is(":radio"))
                error.appendTo(element.parent().parent());
            else if (element.is(":checkbox"))
                error.appendTo(element.parent().parent());
            else
                error.appendTo(element.parent());
        },
        rules : {
            teaQuestionOne :{
                required : true
            },
            teaQuestionTwo : {
                required : true
            },
            agree : "required"
        },
        messages : {
            teaQuestionOne : {
                required : icon + "请选择课堂情况"
            },
            teaQuestionTwo : {
                required : icon + "请选择作业情况"
            }
        }
    })
}